<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table id="table1" border="1" cellspacing="0" cellpadding="1">
			<tr>
				<th></th>
				<th>姓名</th>
				<th>性别</th>
				<th>地址</th>
				<th>电话</th>
				</tr>
				<tr>
				<th> <input type="checkbox" name="" id="" value="" />  </th>
				<th>张三</th>
				<th>男</th>
				<th>江西南昌</th>
				<th>110</th>
				</tr>
				<tr>
				<th> <input type="checkbox" name="" id="" value="" />  </th>
				<th>李四</th>
				<th>女</th>
				<th>四川成都</th>
				<th>120</th>
				</tr>
				<tr>
				<th> <input type="checkbox" name="" id="" value="" />  </th>
				<th>王五</th>
				<th>男</th>
				<th>湖南长沙</th>
				<th>10086</th>
				</tr>
				<tr>
				<th> <input type="checkbox" name="" id="" value="" />  </th>
				<th>赵六</th>
				<th>女</th>
				<th>韩国首尔</th>
				<th>119</th>
				</tr>
				
		</table>
		<input type="checkbox" name="" id="checkall" value="" onclick="checkall()"/>全选 <br>
		<input type="checkbox" name="" id="checkallMan" value="" onclick="checkallMan()"/>全选男 <br>
		<input type="checkbox" name="" id="checkallWoman" value="" onclick="checkallWoman()"/>全选女 <br>
	</body>
	<script type="text/javascript">
		function checkall(){
			var alltable=document.getElementById('table1');
			//console.log(alltable);
			var allinput=alltable.getElementsByTagName('input');
			//console.log(allinput);			
			var checkall=document.getElementById('checkall').checked;
			//console.log(checkall);
			//console.log(allinput.length);
			for (let i = 0; i < allinput.length; i++) {
				allinput[i].checked=checkall;
			}
		}
		function checkallMan(){
			var alltable=document.getElementById('table1');
			//console.log(alltable);
			var allinput=alltable.getElementsByTagName('input');
			//console.log(allinput);			
			var allTr=alltable.getElementsByTagName('tr');
			//console.log(allTr[2]);
			var checkallMan=document.getElementById('checkallMan').checked;
			//console.log(checkallMan);
			//console.log(allinput.length);
			for (let i = 1; i < allTr.length; i++) {
				var allTh=allTr[i].getElementsByTagName('th');
				//console.log(allTh[2].innerText);
				if(allTh[2].innerText=='男'){
					//console.log(allinput[i].checked);
					allinput[i-1].checked=checkallMan;
				}
			}
		}
		function checkallWoman(){
			var alltable=document.getElementById('table1');
			//console.log(alltable);
			var allinput=alltable.getElementsByTagName('input');
			//console.log(allinput);			
			var allTr=alltable.getElementsByTagName('tr');
			//console.log(allTr[2]);
			var checkallWoman=document.getElementById('checkallWoman').checked;
			//console.log(checkallMan);
			//console.log(allinput.length);
			for (let i = 1; i < allTr.length; i++) {
				var allTh=allTr[i].getElementsByTagName('th');
				//console.log(allTh[2].innerText);
				if(allTh[2].innerText=='女'){
					//console.log(allinput[i].checked);
					allinput[i-1].checked=checkallWoman;
				}	
			}
		}
		
	</script>
</html>
